#include "handwidget.h"
#include "ui_handwidget.h"

HandWidget::HandWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HandWidget)
{
    ui->setupUi(this);
    init();
}

HandWidget::~HandWidget()
{
    delete ui;
}

void HandWidget::init()
{
    QString picStyle = "border-image: url(:/new/prefix1/Resource/AutoTop1.png);";
    QString name = "温度监控";
    ui->handBtnTop1->setPicName(picStyle,name);
    ui->handBtnTop1->setIndex(0);
    m_HandBtnMap.insert(name,ui->handBtnTop1);
    //ui->handBtnTop1->setClickedStyle();
    //ui->stackedWidgetHand->setCurrentIndex(0);

    picStyle = "border-image: url(:/new/prefix1/Resource/AutoTop2.png);";
    name = "湿度监控";
    ui->handBtnTop2->setPicName(picStyle,name);
    ui->handBtnTop2->setIndex(1);
    m_HandBtnMap.insert(name,ui->handBtnTop2);

    picStyle = "border-image: url(:/new/prefix1/Resource/AutoTop3.png);";
    name = "光照监控";
    ui->handBtnTop3->setPicName(picStyle,name);
    ui->handBtnTop3->setIndex(2);
    m_HandBtnMap.insert(name,ui->handBtnTop3);

    QMap<QString,HandTopBtn*>::iterator item = m_HandBtnMap.begin();
    while (item != m_HandBtnMap.end()) {

        connect(item.value(),&HandTopBtn::sigClicked,[=](QString name)
        {
            QMap<QString,HandTopBtn*>::Iterator itembtn = m_HandBtnMap.begin();
            while (itembtn != m_HandBtnMap.end()) {
                if(itembtn.key() != name)
                {
                    ((HandTopBtn*)(itembtn.value()))->setNormalStyle();
                }
                itembtn++;
            }
            ui->stackedWidgetHand->setCurrentIndex(m_HandBtnMap.value(name)->getIndex());
        });
        item++;
    }
}
